! SPDX-FileCopyrightText: 2022-2026 Jason Christopherson ! SPDX-License-Identifier: MIT ! ! MIT License ! ! Copyright (c) 2022-2026 Jason Christopherson ! ! Permission is hereby granted, free of charge, to any person obtaining a copy ! of this software and associated documentation files (the "Software"), to deal ! in the Software without restriction, including without limitation the rights ! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ! copies of the Software, and to permit persons to whom the Software is ! furnished to do so, subject to the following conditions: ! ! The above copyright notice and this permission notice shall be included in all ! copies or substantial portions of the Software. ! ! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ! SOFTWARE. module fstats_helper_routines use iso_fortran_env use ieee_arithmetic use fstats_data_columns implicit none private public :: difference public :: factorial public :: column_values contains ! ------------------------------------------------------------------------------ pure function difference(x) result(rst) !! Computes the difference between elements in an array. real(real64), intent(in), dimension(:) :: x !! The N-element array on which to operate. real(real64), allocatable, dimension(:) :: rst !! The (N-1)-element array containing the differences between adjacent !! elements. ! Local Variables integer(int32) :: i, n ! Process n = size(x) allocate(rst(n-1)) do i = 1, n - 1 rst(i) = x(i+1) - x(i) end do end function ! ------------------------------------------------------------------------------ pure elemental function factorial(x) result(rst) !! Computes the factorial of X. real(real64), intent(in) :: x !! The value whose factorial is to be computed. real(real64) :: rst !! The result. rst = gamma(x + 1.0d0) end function ! ------------------------------------------------------------------------------ pure function column_values(x) result(rst) !! Copies a column to a work array for the existing array algorithms. class(data_column), intent(in) :: x !! The input column; unallocated storage is treated as empty. real(real64), allocatable, dimension(:) :: rst !! An independent array with the same count and values as x. If x is !! not a real-valued column, an array of NaN's is returned the same !! size as x. allocate(rst(x%count())) select type (x) class is (real_column) call x%copy(rst) class default rst = ieee_value(0.0d0, ieee_quiet_nan) end select end function ! ------------------------------------------------------------------------------ end module